Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(php): undiscriminated unions #4783

Merged
merged 8 commits into from
Oct 1, 2024

Conversation

dcb6
Copy link
Contributor

@dcb6 dcb6 commented Sep 30, 2024

This PR introduces support in PHP for undiscriminated unions, including the following:

  • serde for undiscriminated union type properties, with types indicated by a Union annotation (the previous Union class was easily converted into an annotation)
  • adding a test for serde of union type properties
  • serde for responses unions
  • serde for requests unions
  • handling union type headers and query parameters

@dcb6 dcb6 marked this pull request as ready for review October 1, 2024 18:24
@dcb6 dcb6 requested a review from dsinghvi as a code owner October 1, 2024 18:24
Copy link
Contributor

@amckinney amckinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Only nits 👏

generators/php/codegen/src/ast/Type.ts Outdated Show resolved Hide resolved
return attributes;
}

public getArrayTypeAttributeArgument(type: php.Type): php.AstNode {
public getUnionTypeClassRepresentation(arguments_: php.AstNode[]): ClassInstantiation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
public getUnionTypeClassRepresentation(arguments_: php.AstNode[]): ClassInstantiation {
public getUnionTypeClassInstantiation(arguments_: php.AstNode[]): ClassInstantiation {

Ideally the argument could be a little more strongly typed (e.g. php.Type). Otherwise it's possible to write in arbitrary php.CodeBlock here. But I know it's difficult because of the getTypeAttributeArgument helper function below - the attributes aren't the same as the type representation (e.g. int vs integer).

Fine with this for now, but we'll need to be careful to call this with arguments that make sense.

generators/php/codegen/src/context/PhpAttributeMapper.ts Outdated Show resolved Hide resolved
generators/php/codegen/src/context/PhpTypeMapper.ts Outdated Show resolved Hide resolved
@dcb6 dcb6 merged commit 4751f47 into main Oct 1, 2024
47 checks passed
@dcb6 dcb6 deleted the burke/fer-3212-php-undiscriminated-unions branch October 1, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants